"""

"""
from time import sleep

# (1) 导入selenium包
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By


def init():
    # (2) 创建浏览器对象
    path = "chromedriver.exe"
    # browser = webdriver.Chrome(path)  # 老版的浏览器传参即是如此，但新版本需要传参为executable_path
    service = Service(executable_path=path)  # 新版传参方式
    browser = webdriver.Chrome(service=service)

    # (3) 访问页面
    url = 'https://www.wjx.cn/vm/hs1zf89.aspx'
    browser.get(url)

    # 点击开始答题
    begin_button = browser.find_element(By.CLASS_NAME, 'slideChunkWord')
    begin_button.click()
    return browser


def topic15(browser):
    topic1 = browser.find_element(By.ID, "q1_3")
    # 通过 JavaScript 执行点击操作
    browser.execute_script("arguments[0].click();", topic1)

    # 找到第一个最外层的 div
    first_outer_div = browser.find_element(By.CLASS_NAME, 'ui-checkbox')
    browser.execute_script("arguments[0].click();", first_outer_div)

    # 找到所有最外层的 div
    all_outer_divs = browser.find_elements(By.CLASS_NAME, 'ui-checkbox')

    # 定义要点击的序号列表(第一题和第五题的答案)
    indices_to_click = [2, 3, 5, 6, 7, 8]
    sleep(2)
    for index, div in enumerate(all_outer_divs):
        if index + 1 in indices_to_click:
            sleep(0.8)
            browser.execute_script("arguments[0].click();", div)


def topic2(browser):
    # 找到所有最外层的 div
    all_outer_divs = browser.find_elements(By.CLASS_NAME, 'ui-radio')
    indices_to_click = [2, 6, 10, 13, 19, 23, 28, 32]
    for index, div in enumerate(all_outer_divs):
        if index + 1 in indices_to_click:
            sleep(0.8)
            browser.execute_script("arguments[0].click();", div)


def topic3(browser):
    all_outer_divs = browser.find_elements(By.CLASS_NAME, 'rate-off')
    indices_to_click = [1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56]
    for index, div in enumerate(all_outer_divs):
        if index + 1 in indices_to_click:
            sleep(0.8)
            browser.execute_script("arguments[0].click();", div)


def submit(browser):
    submit_button = browser.find_element(By.ID, 'ctlNext')
    browser.execute_script("arguments[0].click();", submit_button)

if __name__ == '__main__':
    browser = init()
    # topic15(browser)
    # topic2(browser)
    # topic3(browser)
    submit(browser)
    sleep(1000)



"""
    
第1和5题  
  1题:1~5   
  5题:6~11
# topic15(browser)

题2:1~4
题3:5~9
题6:10~11
题7:12~17
题8:18~22
题9:23~27
题10:28~31
题11:32~37
# topic2(browser)

第四题：
    共12个，一个五个选项
    1-5
    6-10
    11-15
    16-20
    21-25
    26-30
    31-35
    36-40
    41-45
    46-50
    51-55
    56-60
# topic3(browser)
"""